using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XFGameFramework;
using XFFSM;
using XFABManager;
using System;

public class GameController : Controller
{
    public GameModel GetGameModel()
    {
        GameModel model = Module.GetModel<GameModel>();
        if (model == null)
        {
            model = new GameModel();
            Module.AddModel(model);
        }
        return model;
    }
    public int GetCurrentArchiveIndex()
    {
        return GetGameModel().currentArchiveIndex;
    }
    public void SetArchiveIndex(int index)
    {
        GetGameModel().currentArchiveIndex = index;
    }
    public void SetGameState(GameState gameState)
    {
        GetGameModel().gameState = gameState;

        //更新状态机
        FSMController controller = FSMController.GetFSM("GameState");
        if (controller == null)
        {
            //加载并启动状态机
            RuntimeFSMController fsm = AssetBundleManager.LoadAsset<RuntimeFSMController>(Module.ProjectName, "GameState");
            controller = FSMController.StartupFSM("GameState", fsm, Module);
        }

        controller.SetInt("State", (int)gameState);
    }

    public void SetFightState(FightState fightState)
    {
        FSMController fSMController = FSMController.GetFSM("FightState");
        if (fSMController == null)
        {
            RuntimeFSMController fsm = AssetBundleManager.LoadAsset<RuntimeFSMController>(Module.ProjectName, "FightState");
            fSMController = FSMController.StartupFSM("GameState", fsm, Module);
        }
        
        fSMController.SetInt("Fight",(int)fightState);
    }
}
